﻿'use strict';
/*userevaluateCtrl  Controllers */
//诚信记录
app.controller('userevaluateCtrl', ['$http', '$scope', "$state", '$location', '$ngBootbox',"dataService",
    function ($http, $scope, $state, $location, $ngBootbox,dataService) {
        var userId = window.localStorage.id;
        var carcode = $scope.carCode = (window.localStorage.carCode == "null") ? " " : window.localStorage.carCode;

        var credibility = $scope.credibility = "";//诚信度
        var timeliness = $scope.timeliness = "";//时效性
        var attitude = $scope.attitude = "";//服务态度
        var freight = $scope.freight = "";//运输价格
        var average = $scope.average = "";//总分

        $scope.average = "";//平均分
        $scope.praiseCount = "";//好评数量

        $scope.total = "";//总条数
        
        //var average = [];
        $scope.evaluateList = [];

        $scope.isReadonly = true;//只读
        $scope.max = 5;
        $scope.maxSize = 10;

        var goodRating = null;//好评差评筛选初始化
        var skip = $scope.currentPage = 0;
        var count = $scope.pageSize = 10;

        function getList(goodRating, carcode, userId, skip, count) {
            dataService.GetUserRating(goodRating,userId, skip, count )
            //$http.get(Mustache.render("/api/" + "User/GetUserRating?goodRating={{goodRating}}&userId={{userId}}&startIndex={{startIndex}}&count={{count}}", { goodRating: goodRating, userId: userId, startIndex: skip, count: count }))
            .then(function (res) {
                res = res.data.Response;
                $scope.total = res.Total;
                $scope.evaluateList = res.List;
                $scope.totalItems = res.Total;
                $scope.average = res.Average;
                $scope.praiseCount = res.GoodRatingCount;
            }, function (rej) { });
        };

        getList(goodRating, carcode, userId, skip, count);
        //好评、差评、全部数据加载
        $scope.loadData = function (e) {
            switch (e) {
                case 1: return getList(1, carcode, userId, skip, count);
                case 2: return getList(2, carcode, userId, skip, count);
                case 3: return getList(null, carcode, userId, skip, count);
            }
        }

        $scope.pageChanged = function () {
            var currentPage = ($scope.currentPage - 1) * $scope.pageSize
            getList(goodRating, carcode, userId, currentPage, count);
            $scope.evaluateList = [];
        };


    }]);



